﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 数组遍历练习
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //int[] ints = {1, 56, 15, 89, 200};

            //int max = ints[0];

            //for (int i = 0;i < ints.Length;i++)
            //{
            //    if (ints[i] > max)
            //    {
            //        max = ints[i];
            //    }
            //}

            //Console.WriteLine(max);

            int[] scores = {88, 56, 98, 89, 66};

            int maxScore = scores[0];
            int minScore = scores[0];
            int sum = 0;

            for (int i = 0;i < scores.Length;i++)
            {
                //求取最高分
                if (scores[i] > maxScore)
                {
                    maxScore = scores[i];
                }

                //求取最低分
                if (scores[i] < minScore)
                {
                    minScore = scores[i];
                }

                //求取总分
                sum = sum + scores[i];
            }

            //求取低于平均分的学生成绩数量
            int avgScore = sum / scores.Length;
            int count = 0;

            for (int i = 0;i < scores.Length;i++)
            {
                if (scores[i] < avgScore)
                {
                    count++;
                }
            }

            Console.WriteLine("最高成绩为" + maxScore);
            Console.WriteLine("最低成绩为" +  minScore);
            Console.WriteLine("总成绩为" + sum);
            Console.WriteLine("平均分为" + avgScore);
            Console.WriteLine("比平均分低的同学数量" + count);


            Console.WriteLine("----------输出所有学生的成绩 foreach语句-----------");

            //foreach 语句

            //foreach(数据类型 变量名字 in 数组名字)

            //1 如果不使用每个元素的编号的话，可以选择foreach

            //2 foreach当中的n只能够读取访问，不能进行赋值操作

            foreach (int n in scores)
            {
                Console.WriteLine(n);
            }






            Console.Read();
        }
    }
}
